package com.codejiwei.flink.practice;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author jiwei
 * @description
 * @date 2023/5/19 16:26
 */
public class Flink_Transform_Map {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //匿名内部类对象
        env.fromElements(1, 2, 3, 4, 5)
                .map(new MapFunction<Integer, Integer>() {
                    @Override
                    public Integer map(Integer integer) throws Exception {
                        return integer * integer;
                    }
                })
                .print();

        //lambda表达式
//        List<WaterSensor> waterSensors = Arrays.asList(
//                new WaterSensor("ws_001", 1577844001L, 45),
//                new WaterSensor("ws_002", 1577844015L, 43),
//                new WaterSensor("ws_003", 1577844020L, 42)
//        );
//        env.fromCollection(waterSensors)
//                .map(WaterSensor::getId)
//                .print();
//        env.fromElements(1, 2, 3, 4, 5)
//                .map(ele -> ele * ele)
//                .print();

        //静态内部类
//        env.fromElements(1, 2, 3, 4, 5)
//                .map(new RichMapMultiply())
//                .print();

        env.execute("Flink_Transform_Map");
    }
}
